;/*****************************************************************************
; * @file:    startup_MPS_CM3.s
; * @purpose: CMSIS Cortex-M3 Core Device Startup File 
; *           for the ARM 'Microcontroller Prototyping System' 
; * @version: V1.01
; * @date:    19. Aug. 2009
; *------- <<< Use Configuration Wizard in Context Menu >>> ------------------
; *
; * Copyright (C) 2008-2009 ARM Limited. All rights reserved.
; * ARM Limited (ARM) is supplying this software for use with Cortex-M3 
; * processor based microcontrollers.  This file can be freely distributed 
; * within development tools that are supporting such ARM based processors. 
; *
; * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
; * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
; * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
; * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
; * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
; *
; *****************************************************************************/


; <h> Stack Configuration
;   <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Stack_Size      EQU     0x00000400

                AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem       SPACE   Stack_Size
__initial_sp


; <h> Heap Configuration
;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Heap_Size       EQU     0x00000800

                AREA    HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem        SPACE   Heap_Size
__heap_limit


                PRESERVE8
                THUMB


; Vector Table Mapped to Address 0 at Reset

                AREA    RESET, DATA, READONLY
                EXPORT  __Vectors

__Vectors       DCD     __initial_sp              ; Top of Stack
                DCD     Reset_Handler             ; Reset Handler
                DCD     NMI_Handler               ; NMI Handler
                DCD     HardFault_Handler         ; Hard Fault Handler
                DCD     MemManage_Handler         ; MPU Fault Handler
                DCD     BusFault_Handler          ; Bus Fault Handler
                DCD     UsageFault_Handler        ; Usage Fault Handler
                DCD     0                         ; Reserved
                DCD     0                         ; Reserved
                DCD     0                         ; Reserved
                DCD     0                         ; Reserved
                DCD     SVC_Handler               ; SVCall Handler
                DCD     DebugMon_Handler          ; Debug Monitor Handler
                DCD     0                         ; Reserved
                DCD     PendSV_Handler            ; PendSV Handler
                DCD     SysTick_Handler           ; SysTick Handler

	;*===================================================
	;* external interrupt inputs
	;*===================================================
	
;-------------------------------------------Peripheral vectors
				DCD		NULL_Handler					;LVDFAIL_Handler				;0
				DCD		NULL_Handler					;MXOSCFAIL_Handler					;1
				DCD		NULL_Handler					;SXOSCFAIL_Handler					;2
				DCD		NULL_Handler					;WDT_Handler					;3
				DCD		NULL_Handler					;FRT_Handler					;4
				DCD		NULL_Handler					;TIMER0_Handler					;5
				DCD		NULL_Handler					;TIMER1_Handler					;6
				DCD		NULL_Handler					;TIMER2_Handler					;7
				DCD		UART0_Handler					;TIMER3_Handler					;8
				DCD		UART1_Handler					;TIMER4_Handler					;9
				DCD		UART2_Handler					;TIMER5_Handler					;10
				DCD		NULL_Handler					;TIMER6_Handler					;11
				DCD		NULL_Handler					;TIMER7_Handler					;12
				DCD		NULL_Handler					;TIMER8_Handler					;13
				DCD		NULL_Handler					;TIMER9_Handler					;14
				DCD		NULL_Handler					;15
				DCD		NULL_Handler					;GPIOA_Handler					;16
				DCD		NULL_Handler					;GPIOB_Handler					;17
				DCD		NULL_Handler					;GPIOC_Handler					;18
				DCD		NULL_Handler					;GPIOD_Handler					;19
				DCD		NULL_Handler					;GPIOE_Handler					;20
				DCD		NULL_Handler					;GPIOF_Handler					;21
				DCD		NULL_Handler					;22
				DCD		NULL_Handler					;23
				DCD		NULL_Handler					;PWM0_Handler					;24
				DCD		NULL_Handler					;PWM1_Handler					;25
				DCD		NULL_Handler					;PWM2_Handler					;26
				DCD		NULL_Handler					;PWM3_Handler					;27
				DCD		NULL_Handler					;PWM4_Handler					;28
				DCD		NULL_Handler					;PWM5_Handler					;29
				DCD		NULL_Handler					;PWM6_Handler					;30
				DCD		NULL_Handler					;PWM7_Handler					;31
		
				DCD		NULL_Handler					;SPI0_Handler				;32
				DCD		NULL_Handler					;SPI1_Handler					;33
				DCD		NULL_Handler					;SFC_Handler					;34
				DCD		NULL_Handler					;35
				DCD		NULL_Handler					;I2C0_Handler					;36
				DCD		NULL_Handler					;I2C1_Handler					;37
				DCD		NULL_Handler					;UART0_Handler					;38
				DCD		NULL_Handler					;UART1_Handler					;39
				DCD		NULL_Handler					;UART2_Handler					;40
				DCD		NULL_Handler					;UART3_Handler					;41
				DCD		NULL_Handler					;42	
				DCD		NULL_Handler					;ADC_Handler					;43
				DCD		NULL_Handler					;44
				DCD		NULL_Handler					;46
				DCD		NULL_Handler					;47
				DCD		NULL_Handler					;48
				DCD		NULL_Handler					;49
				DCD		NULL_Handler					;40
				DCD		NULL_Handler					;50
				DCD		NULL_Handler					;51
				DCD		NULL_Handler					;52
				DCD		NULL_Handler					;53
				DCD		NULL_Handler					;54
				DCD		NULL_Handler					;55
				DCD		NULL_Handler					;56
				DCD		NULL_Handler					;57
				DCD		NULL_Handler					;58
				DCD		NULL_Handler					;59
				DCD		NULL_Handler					;60
				DCD		NULL_Handler					;61
				DCD		NULL_Handler					;62
				DCD		NULL_Handler					;63

;//--------------------------------------------------------------------



                AREA    |.text|, CODE, READONLY


; Reset Handler

Reset_Handler   PROC
                EXPORT  Reset_Handler             [WEAK]
                IMPORT  __main
                LDR     R0, =__main
                BX      R0
                ENDP


; Dummy Exception Handlers (infinite loops which can be modified)

NMI_Handler     PROC
                EXPORT  NMI_Handler               [WEAK]
                B       .
                ENDP
HardFault_Handler\
                PROC
                EXPORT  HardFault_Handler         [WEAK]
                B       .
                ENDP
MemManage_Handler\
                PROC
                EXPORT  MemManage_Handler         [WEAK]
                B       .
                ENDP
BusFault_Handler\
                PROC
                EXPORT  BusFault_Handler          [WEAK]
                B       .
                ENDP
UsageFault_Handler\
                PROC
                EXPORT  UsageFault_Handler        [WEAK]
                B       .
                ENDP
SVC_Handler     PROC
                EXPORT  SVC_Handler               [WEAK]
                B       .
                ENDP
DebugMon_Handler\
                PROC
                EXPORT  DebugMon_Handler          [WEAK]
                B       .
                ENDP
PendSV_Handler  PROC
                EXPORT  PendSV_Handler            [WEAK]
                B       .
                ENDP
SysTick_Handler PROC
                EXPORT  SysTick_Handler           [WEAK]
                B       .
                ENDP

NULL_Handler PROC

                EXPORT  UART0_Handler          [WEAK]
                EXPORT  UART1_Handler          [WEAK]
                EXPORT  UART2_Handler          [WEAK]

UART0_Handler
UART1_Handler
UART2_Handler
                B       .

                ENDP


                ALIGN


; User Initial Stack & Heap

                IF      :DEF:__MICROLIB
                
                EXPORT  __initial_sp
                EXPORT  __heap_base
                EXPORT  __heap_limit
                
                ELSE
                
                IMPORT  __use_two_region_memory
                EXPORT  __user_initial_stackheap
__user_initial_stackheap

                LDR     R0, =  Heap_Mem
                LDR     R1, =(Stack_Mem + Stack_Size)
                LDR     R2, = (Heap_Mem +  Heap_Size)
                LDR     R3, = Stack_Mem
                BX      LR

                ALIGN

                ENDIF


                END
